

************************
** Study 2: Figure S2.20
************************



** 2017 Results
***************

* Covariates macro
global covars_binaries = "gender1 gender2 gender3 agecat1 agecat2 agecat3 agecat4 agecat5 agecat6 edu1 edu2 edu3 edu4 edu5 edu6 pol_interest1 pol_interest2 pol_interest3 pol_interest4 lr0 lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 vote2015_1 vote2015_2 vote2015_3 vote2015_4 vote2015_5 vote2015_6 vote2015_7 vote2015_8 vote2015_9 vote2015_10 refvote2016_1 refvote2016_2 refvote2016_3 region1 region2 region3"

* Open dataset
use "LondonBridgeAttack2017.dta", replace

* Normalize items
replace imm1 = (imm1 - 1) * 25
replace imm2 = (imm2 - 1) * 25
replace imm3 = (imm3 - 1) * 25

* Regressions
foreach dv of varlist sec imm1 imm2 imm3 {
reg `dv' postattack $covars_binaries if statadate == td(02jun2017) | statadate == td(04jun2017)
estimates store `dv'1
reg `dv' postattack $covars_binaries if inrange(statadate,td(01jun2017),td(02jun2017)) | inrange(statadate,td(04jun2017),td(05jun2017))
estimates store `dv'2
reg `dv' postattack $covars_binaries if inrange(statadate,td(31may2017),td(02jun2017)) | inrange(statadate,td(04jun2017),td(06jun2017))
estimates store `dv'3
}

* Results table
gen days = _n in 1/3
foreach dv of varlist sec imm1 imm2 imm3 {
gen n_`dv' = .
gen pe_`dv' = .
gen se_`dv' = .
gen p_`dv' = .
gen ll_`dv' = .
gen ul_`dv' = .
sum `dv'
gen sd_`dv' = `r(sd)'
gen d_`dv' = .
gen dlow_`dv' = .
gen dup_`dv' = .
forvalues i = 1/3 {
estimates restore `dv'`i'
replace n_`dv' = `e(N)' if days == `i'
estimates replay `dv'`i'
matrix R = r(table)
replace pe_`dv' = R[1,1] if days == `i'
replace se_`dv' = R[2,1] if days == `i'
replace p_`dv' = R[4,1] if days == `i'
replace ll_`dv' = R[5,1] if days == `i'
replace ul_`dv' = R[6,1] if days == `i'
replace d_`dv' = pe_`dv'/sd_`dv' if days == `i'
replace dlow_`dv' = pe_`dv'/sd_`dv' - 1.96*se_`dv'/sd_`dv' if days == `i'
replace dup_`dv' = pe_`dv'/sd_`dv' + 1.96*se_`dv'/sd_`dv' if days == `i'
}
}

drop newid - referrer
drop _est*
keep in 1/3
gen year = 2017
order year

save "ItemByItem2017.dta", replace




** 2019 Results
***************

* Covariates macro
global covars_binaries = "gender1 gender2 gender3 agecat1 agecat2 agecat3 agecat4 agecat5 agecat6 edu1 edu2 edu3 edu4 edu5 edu6 pol_interest1 pol_interest2 pol_interest3 lr0 lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 vote2017_1 vote2017_2 vote2017_3 vote2017_4 vote2017_5 vote2017_6 vote2017_7 vote2017_8 vote2017_9 vote2017_10 vote2017_11 refvote2016_1 refvote2016_2 refvote2016_3 refvote2016_4 region1 region2 region3"

* Open dataset
use "LondonBridgeAttack2019.dta", replace

* Normalize items
replace sec1 = (sec1 - 1) * 25
replace sec2 = (sec2 - 1) * 25
replace imm1 = (imm1 - 1) * 25
replace imm2 = (imm2 - 1) * 25
replace imm3 = (imm3 - 1) * 25
replace imm4 = (imm4 - 1) * 25

* Regressions
foreach dv of varlist sec1 sec2 imm1 imm2 imm3 imm4 {
reg `dv' postattack $covars_binaries if statadate == td(28nov2019) | statadate == td(30nov2019)
estimates store `dv'1
reg `dv' postattack $covars_binaries if inrange(statadate,td(27nov2019),td(28nov2019)) | inrange(statadate,td(30nov2019),td(1dec2019))
estimates store `dv'2
reg `dv' postattack $covars_binaries if inrange(statadate,td(26nov2019),td(28nov2019)) | inrange(statadate,td(30nov2019),td(2dec2019))
estimates store `dv'3
}

* Results table
gen days = _n in 1/3
foreach dv of varlist sec1 sec2 imm1 imm2 imm3 imm4 {
gen n_`dv' = .
gen pe_`dv' = .
gen se_`dv' = .
gen p_`dv' = .
gen ll_`dv' = .
gen ul_`dv' = .
sum `dv'
gen sd_`dv' = `r(sd)'
gen d_`dv' = .
gen dlow_`dv' = .
gen dup_`dv' = .
forvalues i = 1/3 {
estimates restore `dv'`i'
replace n_`dv' = `e(N)' if days == `i'
estimates replay `dv'`i'
matrix R = r(table)
replace pe_`dv' = R[1,1] if days == `i'
replace se_`dv' = R[2,1] if days == `i'
replace p_`dv' = R[4,1] if days == `i'
replace ll_`dv' = R[5,1] if days == `i'
replace ul_`dv' = R[6,1] if days == `i'
replace d_`dv' = pe_`dv'/sd_`dv' if days == `i'
replace dlow_`dv' = pe_`dv'/sd_`dv' - 1.96*se_`dv'/sd_`dv' if days == `i'
replace dup_`dv' = pe_`dv'/sd_`dv' + 1.96*se_`dv'/sd_`dv' if days == `i'
}
}

drop id - region3
drop _est*
keep in 1/3
gen year = 2019
order year

save "ItemByItem2019.dta", replace





** Figure
*********


* Bring data in correct shape
use "ItemByItem2017.dta", replace
set obs 15
sum year
replace year = `r(mean)'
gen row = _n
gen outcome = ""
gen pe = .
gen ll = .
gen ul = .
gen n = .
forvalues i = 1/3 {
	replace outcome = "sec1" if row == `i' + 3
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 3
	sum d_sec if row == `i'
	replace pe = `r(mean)' if row == `i' + 3
	sum dlow_sec if row == `i'
	replace ll = `r(mean)' if row == `i' + 3
	sum dup_sec if row == `i'
	replace ul = `r(mean)' if row == `i' + 3
	sum n_sec if row == `i'
	replace n = `r(mean)' if row == `i' + 3
}
forvalues i = 1/3 {
	replace outcome = "imm1" if row == `i' + 6
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 6
	sum d_imm1 if row == `i'
	replace pe = `r(mean)' if row == `i' + 6
	sum dlow_imm1 if row == `i'
	replace ll = `r(mean)' if row == `i' + 6
	sum dup_imm1 if row == `i'
	replace ul = `r(mean)' if row == `i' + 6
	sum n_imm1 if row == `i'
	replace n = `r(mean)' if row == `i' + 6
}
forvalues i = 1/3 {
	replace outcome = "imm2" if row == `i' + 9
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 9
	sum d_imm2 if row == `i'
	replace pe = `r(mean)' if row == `i' + 9
	sum dlow_imm2 if row == `i'
	replace ll = `r(mean)' if row == `i' + 9
	sum dup_imm2 if row == `i'
	replace ul = `r(mean)' if row == `i' + 9
	sum n_imm2 if row == `i'
	replace n = `r(mean)' if row == `i' + 9
}
forvalues i = 1/3 {
	replace outcome = "imm3" if row == `i' + 12
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 12
	sum d_imm3 if row == `i'
	replace pe = `r(mean)' if row == `i' + 12
	sum dlow_imm3 if row == `i'
	replace ll = `r(mean)' if row == `i' + 12
	sum dup_imm3 if row == `i'
	replace ul = `r(mean)' if row == `i' + 12
	sum n_imm3 if row == `i'
	replace n = `r(mean)' if row == `i' + 12
}
drop in 1/3
drop n_sec - row
save temp2017.dta, replace




use "ItemByItem2019.dta", replace
set obs 21
sum year
replace year = `r(mean)'
gen row = _n
gen outcome = ""
gen pe = .
gen ll = .
gen ul = .
gen n = .
forvalues i = 1/3 {
	replace outcome = "sec1" if row == `i' + 3
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 3
	sum d_sec1 if row == `i'
	replace pe = `r(mean)' if row == `i' + 3
	sum dlow_sec1 if row == `i'
	replace ll = `r(mean)' if row == `i' + 3
	sum dup_sec1 if row == `i'
	replace ul = `r(mean)' if row == `i' + 3
	sum n_sec1 if row == `i'
	replace n = `r(mean)' if row == `i' + 3
}
forvalues i = 1/3 {
	replace outcome = "sec2" if row == `i' + 6
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 6
	sum d_sec2 if row == `i'
	replace pe = `r(mean)' if row == `i' + 6
	sum dlow_sec2 if row == `i'
	replace ll = `r(mean)' if row == `i' + 6
	sum dup_sec2 if row == `i'
	replace ul = `r(mean)' if row == `i' + 6
	sum n_sec2 if row == `i'
	replace n = `r(mean)' if row == `i' + 6
}
forvalues i = 1/3 {
	replace outcome = "imm1" if row == `i' + 9
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 9
	sum d_imm1 if row == `i'
	replace pe = `r(mean)' if row == `i' + 9
	sum dlow_imm1 if row == `i'
	replace ll = `r(mean)' if row == `i' + 9
	sum dup_imm1 if row == `i'
	replace ul = `r(mean)' if row == `i' + 9
	sum n_imm1 if row == `i'
	replace n = `r(mean)' if row == `i' + 9
}
forvalues i = 1/3 {
	replace outcome = "imm2" if row == `i' + 12
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 12
	sum d_imm2 if row == `i'
	replace pe = `r(mean)' if row == `i' + 12
	sum dlow_imm2 if row == `i'
	replace ll = `r(mean)' if row == `i' + 12
	sum dup_imm2 if row == `i'
	replace ul = `r(mean)' if row == `i' + 12
	sum n_imm2 if row == `i'
	replace n = `r(mean)' if row == `i' + 12
}
forvalues i = 1/3 {
	replace outcome = "imm3" if row == `i' + 15
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 15
	sum d_imm3 if row == `i'
	replace pe = `r(mean)' if row == `i' + 15
	sum dlow_imm3 if row == `i'
	replace ll = `r(mean)' if row == `i' + 15
	sum dup_imm3 if row == `i'
	replace ul = `r(mean)' if row == `i' + 15
	sum n_imm3 if row == `i'
	replace n = `r(mean)' if row == `i' + 15
}
forvalues i = 1/3 {
	replace outcome = "imm4" if row == `i' + 18
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 18
	sum d_imm4 if row == `i'
	replace pe = `r(mean)' if row == `i' + 18
	sum dlow_imm4 if row == `i'
	replace ll = `r(mean)' if row == `i' + 18
	sum dup_imm4 if row == `i'
	replace ul = `r(mean)' if row == `i' + 18
	sum n_imm4 if row == `i'
	replace n = `r(mean)' if row == `i' + 18
}
drop in 1/3
drop n_sec1 - row
save temp2019.dta, replace


* Merge 2017 and 2019
use temp2017.dta, replace
append using temp2019.dta

* Graph preparations
gen ntext = "{it:N} = "
tostring n, replace
replace ntext = ntext + n
gen ypos = .
replace ypos = 0.70 if days == 1
replace ypos = 0.50 if days == 2
replace ypos = 0.30 if days == 3
replace ypos = ypos + 5 if outcome == "sec1"
replace ypos = ypos + 4 if outcome == "sec2"
replace ypos = ypos + 3 if outcome == "imm1"
replace ypos = ypos + 2 if outcome == "imm2"
replace ypos = ypos + 1 if outcome == "imm3"
gen x = 0.30


* Graph
twoway ///
	(scatter ypos pe if days == 1, mcolor(gs12) msymbol(o) msize(medium)) ///
	(rspike ll ul ypos if days == 1, lcolor(gs12) horizontal) ///
	(scatter ypos pe if days == 2, mcolor(gs7) msymbol(s) msize(medium)) ///
	(rspike ll ul ypos if days == 2, lcolor(gs7) horizontal) ///
	(scatter ypos pe if days == 3, mcolor(gs2) msymbol(t) msize(medium)) ///
	(rspike ll ul ypos if days == 3, lcolor(gs2) horizontal) ///
	(scatter ypos x, msymbol(none) mlabel(ntext) mlabsize(vsmall) mlabangle(horizontal) mlabposition(3)) ///
	, ///
	by(year, noixlabel ixtitle graphregion(fcolor(white) lcolor(white)) bgcolor(white) note("{it:Note:} The spikes represent 95% confidence intervals.") legend(pos(6))) ///
	ytitle("") yscale(noline range(0 6)) ///
	ylabel(5.5 "{it:sec1}" 4.5 "{it:sec2}" 3.5 "{it:imm1}" 2.5 "{it:imm2}" 1.5 "{it:imm3}" 0.5 "{it:imm4}", angle(horizontal) nogrid) ///
	xtitle("Effect on political attitudes (Cohen's {it:d})", margin(small))  ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	xlabel(-0.10(.10).40,) xmlabel(-0.10(0.05)0.40, ) xscale(noline) ///
	legend(order(1 3 5) label(1 "± 1 day") label(3 "± 2 days") label(5 "± 3 days") rows(1) size(small) keygap(*1) region(lstyle(none) lcolor(white))) ///
	subtitle(, size(large) align(middle) margin(bottom) nobox fcolor(white))  ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(6) ysize(3.5)
gr_edit .b1title.draw_view.setstyle, style(no)
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(show_labels(yes))) editcopy
gr_edit .legend.DragBy 0 12
gr_edit .gmetric_mult = 1.15





** Tidy Up
**********

erase "ItemByItem2017.dta"
erase "ItemByItem2019.dta"
erase temp2017.dta
erase temp2019.dta

